require('../css/course-detail.less');
document.ready(function () {
    // 返回
    const iconfont = document.querySelector('.iconfont');
    iconfont.addEventListener('click', function () {
        window.history.back();
    })
    // 获取id
    const userId = JSON.parse(window.localStorage.getItem('user')).user.userId;
    // 获取节点
    const courseBtn = document.querySelector('#courseBtn');
    // 标题
    const topTitle = document.querySelector('#topTitle');
    //千卡
    const courseKg = document.querySelector('#courseKg');
    // 练习人数
    const courseNum = document.querySelector('#courseNum');
    //分钟
    const courseTime = document.querySelector('#courseTime');
    //讲解
    const courseData = document.querySelector('#courseData');
    //练习频次
    const frequency = document.querySelector('#frequency');
    let courseId = window.location.search.split('=')[1];
    //请求课程详情数据
    $http.get(`/sports/courseDetail?id=${courseId}`, function (res) {
        if (res.status === 0) {
            const latestCourseData = res.data;
            // 页面渲染
            topTitle.textContent = latestCourseData.name;
            courseKg.textContent = latestCourseData.calorie;
            courseTime.textContent = latestCourseData.time;
            courseNum.textContent = latestCourseData.peoplenum;
            courseData.textContent = latestCourseData.desc;
            frequency.textContent = latestCourseData.frequency;
            localStorage.setItem('fragments',JSON.stringify(latestCourseData));
        }
    })
    courseBtn.addEventListener('click', function () {
        window.location.href = `./player.html?courseId=${courseId}`;
    })
});